package by.yakusekmaxim.bookgid.webapp.page;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

import by.yakusekmaxim.bookgid.webapp.page.admin.ConsolePage;
import by.yakusekmaxim.bookgid.webapp.page.admin.autor.AuthorPage;
import by.yakusekmaxim.bookgid.webapp.page.admin.book.BookPage;
import by.yakusekmaxim.bookgid.webapp.page.admin.genre.GenrePage;
import by.yakusekmaxim.bookgid.webapp.page.admin.image.ImagePage;
import by.yakusekmaxim.bookgid.webapp.page.admin.series.SeriesPage;
import by.yakusekmaxim.bookgid.webapp.page.admin.user.UserPage;
import by.yakusekmaxim.bookgid.webapp.page.home.HomePage;

public abstract class AdminLayout extends WebPage {
	
	protected  WebMarkupContainer targetConsole = new WebMarkupContainer("targetConsole");
	protected  WebMarkupContainer targetAutor = new WebMarkupContainer("targetAutor");
	protected  WebMarkupContainer targetBook = new WebMarkupContainer("targetBook");
	protected  WebMarkupContainer targetGenre = new WebMarkupContainer("targetGenre");
	protected  WebMarkupContainer targetSeries = new WebMarkupContainer("targetSeries");
	protected  WebMarkupContainer targetImage = new WebMarkupContainer("targetImage");
	protected  WebMarkupContainer targetUser = new WebMarkupContainer("targetUser");
	
	@Override
	protected void onInitialize() {
		super.onInitialize();

		add(new Label("headerTitle", getPageTitle()));
		add(new BookmarkablePageLink<Void>("linkHomePage", HomePage.class));
	
		getTarget().add(AttributeModifier.replace("class", "targetli"));
		add(targetConsole);
		targetConsole.add(new Link<Object>("linkConsolePage") {
			@Override
			public void onClick() {
				ConsolePage consolePage = new ConsolePage();
				setResponsePage(consolePage);
			}
		});
		
		add(targetAutor);
		targetAutor.add(new Link<Object>("linkAutorPage") {
			@Override
			public void onClick() {
				AuthorPage autorPage = new AuthorPage();
				setResponsePage(autorPage);
			}
		});
		
		add(targetBook);
		targetBook.add(new Link<Object>("linkBookPage") {
			@Override
			public void onClick() {
				BookPage bookPage = new BookPage();
				setResponsePage(bookPage);
			}
		});
		
		add(targetGenre);
		targetGenre.add(new Link<Object>("linkGenrePage"){

			@Override
			public void onClick() {
				GenrePage genrePage = new GenrePage();
				setResponsePage(genrePage);
				
			}
			
		});
		
		add(targetSeries);
		targetSeries.add(new Link<Object>("linkNewsPage"){

			@Override
			public void onClick() {
				SeriesPage newsPage = new SeriesPage();
				setResponsePage(newsPage);
				
			}
			
		});
		
		add(targetImage);
		targetImage.add(new Link<Object>("linkImagePage"){

			@Override
			public void onClick() {
				ImagePage imagePage = new ImagePage();
				setResponsePage(imagePage);
				
			}
			
		});
		
		add(targetUser);
		targetUser.add(new Link<Object>("linkUserPage"){

			@Override
			public void onClick() {
				UserPage userPage = new UserPage();
				setResponsePage(userPage);
				
			}
			
		});
		
		add(new FeedbackPanel("feedbackpanel"));
	}
		
	protected abstract WebMarkupContainer getTarget();

	protected IModel<String> getPageTitle() {
		return new Model<String>(getClass().getSimpleName());
	}

}
